func minDays(bloomDay []int, m int, k int) int {
	n := len(bloomDay)
	if n < m*k {
		return -1
	}
	left := bloomDay[0]
	right := 0
	// 计算二分的上下边界
	for _, value := range bloomDay {
		if value < left {
			left = value
		}
		if value > right {
			right = value
		}
	}
	// 二分迭代模板
	for left <= right {
		mid := left + (right-left)/2
		//如果mid满足条件缩小right，反之增大left
		if minDaysValid(bloomDay, m, k, mid) {
			right = mid - 1
		} else {
			left = mid + 1
		}
	}
	return left
}

// 判断是否合法
func minDaysValid(bloomDay []int, m int, k int, day int) bool {
	block := make([]int, len(bloomDay))
	index := 0
	for i := 0; i < len(bloomDay); i++ {
		if day >= bloomDay[i] {
			block[index]++
		} else {
			index++
		}
	}
	count := 0
	for i := range block {
		count += block[i] / k
	}
	if count >= m {
		return true
	}
	return false
}